home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
manchest.lha
/
MANCHESTER
/
manchester
/
2.2
/
fibonacci.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
2KB
|
55 lines
" NAME fibonacci
AUTHOR TPH@cs.man.ac.uk
FUNCTION serial & parallel versions
ST-VERSIONS 2.2
PREREQUISITES Parallelism
CONFLICTS
DISTRIBUTION world
VERSION 1.1
DATE 22 Jan 1989
SUMMARY fibonacci
contains both a serial and a parallel version of a
fibonacci number method for class Integer. To make the parallel
version work, you should have filed in Parallelism.st first.(2.2). TPH
"!
'From Smalltalk-80, Version 2.2 of July 4, 1987 on 26 November 1987 at 11:23:06 am'!
!BlockContext methodsFor: 'parallel evaluation'!
parallelAdd: aBlock
"Executes the receiver in parallel with aBlock. Once both
have completed, perform an ADD operation."
| first second |
first _ self futureValue.
second _ aBlock futureValue.
^first touch + second touch! !
'From Smalltalk-80, Version 2.2 of July 4, 1987 on 25 November 1987 at 4:40:55 pm'!
!Integer methodsFor: 'mathematical functions'!
fibonacci
"Recursively generate fibonacci number of receiver."
self <= 1 ifTrue:[^1]
ifFalse:[^(self - 1) fibonacci + (self - 2) fibonacci + 1]
"Transcript cr; show: 20 fibonacci printString."
"Transcript cr; show: (Time millisecondsToRun: [20 fibonacci]) printString."!
parallelFibonacci
"Recursively generate fibonacci number of receiver. Use an
explicit parallel algorithm."
self <= 1 ifTrue:[^1]
ifFalse:[^[(self - 1) parallelFibonacci] parallelAdd:
[(self - 2) parallelFibonacci + 1]]
"Transcript cr; show: 20 parallelFibonacci printString."
"Transcript cr; show: (Time millisecondsToRun: [20 parallelFibonacci]) printString."! !